<?php
/**
 * 设置271
 */
apf_require_controller("Abstract");
apf_require_class("Bll_Jx_Setting");
apf_require_class("Util_ApioAuth");
class Setting_ShowUserTreeActionController extends AbstractController {
    public function handle_request() {
        $params=APF::get_instance()->get_request()->get_parameters('type');
        $code="SHA001";
        $flag;
        $data=$this->get_subordinate_infor($code);
        $underlings=$this->get_data_format($data);
        if($params['flag']=="check")
        {
         $bll= new Bll_Jx_Setting();
         $flag=$bll->get_user_info($params["leaderName"]);
         if(!$flag)
         APF::get_instance()->get_response()->redirect("/setting/SetBrantchLeader/");
        }
        APF::get_instance()->get_request()->set_attribute("underlings",$underlings);
        APF::get_instance()->get_request()->set_attribute("next",$params["type"]);
        APF::get_instance()->get_request()->set_attribute("leaderName",$params["leaderName"]);
        APF::get_instance()->get_request()->set_attribute("user_id",$flag[0]["user_id"]);
        return 'Setting_ShowUserTreeAction';
    }
    public function get_data_format($data){
        $tmp=json_decode($data,true);
                $underling=array();
        foreach ($tmp[0]['subordinate'] as $sub){
                if($sub!=null)
                {
                 array_push($underling,array("name"=>$sub['name'],"code"=>$sub['code']));
                }
        }
        return $underling;
    }
    public function get_subordinate_infor($code){
        return Util_ApioAuth::get_user_info_by_api($code);
    }
}